# -*- coding:utf-8 -*-
import requests
import time,Land

class RequestAssertion():
    #main_url_admin = 'http://admin-service-api.yhtest0.com/'
    #token_admin = Land.token()


    def request(self,method,url,data=None,headers=None):
        if data is None:
            data={}
        if headers is None:
            headers={}
        #headers = {'Authorization': 'Bearer ' + RequestAssertion().token_admin}

        respones = {}
        if method == "get":
            respones = requests.get(url=url, headers=headers)
        elif method == "post_x":
            respones = requests.post(url=url, data=data, headers=headers)
        elif method == "post":
            respones = requests.post(url=url,json=data, headers=headers)
        elif method == "put":
            respones = requests.put(url=url, json=data, headers=headers)
        elif method == "patch":
            respones = requests.patch(url=url, json=data, headers=headers)
        elif method == "del":
            respones = requests.delete(url=url, json=data, headers=headers)
        return respones

    # 接口耗时
    def consuming(self,respones,interfaceName):
        time.sleep(1)
        return interfaceName + ",Interface time:{}".format(respones.elapsed.total_seconds())




